import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:study_app/tools/app_color.dart';

class MaxTextView extends StatelessWidget {
  final String? title;
  final String? hintText;
  final String? defaultValue;
  final double? height;
  final void Function(String) onChangeText;
  final Color fillcolor;
  final int? length;

  MaxTextView(
      {this.title,
      this.hintText,
      this.defaultValue,
      this.height = 100,
      this.fillcolor = backgroundColor,
      this.length,
      required this.onChangeText});

  @override
  Widget build(BuildContext context) {
    return Container(
      //padding: EdgeInsets.all(16),
      color: Colors.red,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: _childNodes(),
      ),
    );
  }

  _childNodes() {
    List<Widget> arr = [];

    if (title != null) {
      arr.add(Text(
        title!,
        style: const TextStyle(color: Color(0xFF333333), fontSize: 16),
      ));
    }
    TextEditingController controller = TextEditingController();
    if ((defaultValue ?? "").isNotEmpty) {
      controller.text = defaultValue!;
    }
    List<Widget> g = [
      Container(
        padding: const EdgeInsets.only(bottom: 10),
        height: height,
        child: TextField(
          controller: controller,
          onChanged: (String text) {
            if (text.length > 3600) {
            } else {
              onChangeText(text);
            }
          },
          decoration: InputDecoration(
            fillColor: fillcolor,
            filled: true,
            hintText: hintText,
            border: InputBorder.none,
          ),
          keyboardType: TextInputType.multiline,
          maxLines: 100,
          maxLength: length,
        ),
      )
    ];

    arr.addAll(g);
    return arr;
  }
}
